package cn.bocweb.spinning.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ExChangeListBean;

/**
 * Created by chenchangxing on 16/7/13.
 */
public class MyIntegralRechargeAdapter extends RecyclerView.Adapter {

    List<ExChangeListBean.DataBean> list;
    OnClickListener onClickListener;

    public MyIntegralRechargeAdapter(List<ExChangeListBean.DataBean> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_integral_recharge, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        ViewHolder holder1 = (ViewHolder) holder;
        Glide
                .with(holder.itemView.getContext())
                .load(list.get(position).getPhoto())
                .placeholder(R.mipmap.banner_empty)
                .into(holder1.imageviewPhoto);

        String status = list.get(position).getAudit().equals("0") ? "等待兑换" : "兑换成功";

        holder1.textviewTitle.setText(list.get(position).getTitle());
        holder1.textviewScore.setText(list.get(position).getScore());
        holder1.textviewState.setText(status);

        holder1.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickListener.click(
                        list.get(holder.getAdapterPosition()).getUrl(),
                        holder.getAdapterPosition(),
                        list.get(holder.getAdapterPosition()).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.imageview_photo)
        ImageView imageviewPhoto;
        @Bind(R.id.textview_title)
        TextView textviewTitle;
        @Bind(R.id.textview_score)
        TextView textviewScore;
        @Bind(R.id.textview_state)
        TextView textviewState;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface OnClickListener {
        void click(String url, int position, String id);
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
